package com.example.smart_community.service;

import com.example.smart_community.mapper.MaintainrequestMapper;
import com.example.smart_community.mapper.RepairorderMapper;
import com.example.smart_community.model.MessageModel;
import com.example.smart_community.po.Maintainrequest;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MaintainrequestService {
    @Autowired
    private MaintainrequestMapper maintainrequestMapper;
    @Autowired
    private RepairorderMapper repairorderMapper;

    public int  insertData(String name, String phone, String content,Integer hId,String address,String requesttime){
        if(hId!=null){
             int n= maintainrequestMapper.insert1(name, phone, content, hId,requesttime);
              System.out.println(n);
              if(n>0){
                 Maintainrequest maintainrequest= maintainrequestMapper.selectByNameAndRequesttime(name,requesttime);
                  System.out.println(maintainrequest);
                 int m=repairorderMapper.insertRepairorder(maintainrequest.getId(), 1);
                 if(m>0){
                     return 2;
                 }
              }
              return n;
        }else{
             if(address!=null||!"".equals(address)){
                 int n= maintainrequestMapper.insert2(name, phone, content, address,requesttime);
                 System.out.println(n);
                 System.out.println(requesttime);
                 if(n>0){
                     Maintainrequest maintainrequest= maintainrequestMapper.selectByNameAndRequesttime(name,requesttime);
                     System.out.println(maintainrequest);
                     int m=repairorderMapper.insertRepairorder(maintainrequest.getId(), 1);
                     if(m>0){
                         return 2;
                     }
                 }
                 return n;
             }else{
                 return 0;
             }
        }
    }
}
